//
//  HXSearchBar.m
//  新浪微博
//
//  Created by Hubery on 15/8/15.
//  Copyright (c) 2015年 Whx. All rights reserved.
//

#import "HXSearchBar.h"

@implementation HXSearchBar

+(instancetype)searchBar
{
    return [[self alloc]init];
}
-(id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // 在这里创建
        UIImageView *leftView = [[UIImageView alloc]init];
        leftView.image = [UIImage imageNamed:@"searchbar_textfield_search_icon"];
        leftView.frame = CGRectMake(0, 0, leftView.image.size.width+10, leftView.image.size.height);//图片大小
        //设置leftView内容居中
        leftView.contentMode = UIViewContentModeCenter;
        self.background = [UIImage resizedImage:@"searchbar_textfield_background"];
        //设置内容垂直居中  想要找属性 到头文件中找 如果没有到父类头文件里面找
        //内容的垂直方向对齐 上下居中 UIController 的属性
        self.contentVerticalAlignment = UIControlContentHorizontalAlignmentCenter;
        self.leftView = leftView;
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 26, 26)];
        [btn setBackgroundImage:[UIImage imageWithOriginalName:@"666"] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        btn.contentMode = UIViewContentModeCenter;
        self.rightView = btn;
        
        //设置右边的全部删除叉叉
        //self.clearButtonMode = UITextFieldViewModeAlways;
        self.leftViewMode = UITextFieldViewModeAlways;
        self.rightViewMode = UITextFieldViewModeAlways;
    }
    return self;
}

-(void)btnClick
{
    if([self.searchDelegate respondsToSelector:@selector( searchBarDidQrCode:)])//判断代理有没有实现这个方法
    {
        [self.searchDelegate searchBarDidQrCode:self];
    }
}
@end
